package com.pascualabs.android.lwplantilla;

import android.app.Activity;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

	public class LiveWallpaperSettings extends Activity implements OnCheckedChangeListener{
	
		private RadioGroup radioBackgroundGroup;
		private RadioButton radioBackgroundButton;
		private String mBackground;
		private int id;

		
		@Override
		protected void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			this.setContentView(R.layout.prefs);			
			radioBackgroundGroup = (RadioGroup) findViewById(R.id.radioBackground);	
			radioBackgroundGroup.setOnCheckedChangeListener(this);	
			//if(LiveWallpaperPreferences.getInstance().getBackground() != null){
				id = LiveWallpaperPreferences.getInstance().getBackgroundId();
				if(id != -1){
					radioBackgroundButton= (RadioButton)findViewById(id);
					radioBackgroundButton.setChecked(true);
				}
			//}
			
		}

		@Override
		protected void onPause() {
			// onPause(), we save the current value to the preference file.
			if(mBackground != "" && id != -1){
				LiveWallpaperPreferences.getInstance().setBackground(mBackground,id);
			}
			super.onPause();
		}

		@Override
		public void onCheckedChanged(RadioGroup group, int selectedId) {
			// TODO Auto-generated method stub

		selectedId = radioBackgroundGroup.getCheckedRadioButtonId();
		id = selectedId;
		radioBackgroundButton = (RadioButton) findViewById(selectedId);
		mBackground = (String) radioBackgroundButton.getText();	
		}

	}
		